package com.ledi.guns;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.ledi.guns.config.properties.GunsProperties;

/**
 * SpringBoot方式启动类
 *
 * @author ledi
 * @Date 2017/5/21 12:06
 */

@EnableFeignClients
@EnableEurekaClient
@SpringBootApplication
@EnableCaching
public class PayApplication extends WebMvcConfigurerAdapter {

	protected final static Logger logger = LoggerFactory.getLogger(PayApplication.class);

	@Autowired
	GunsProperties gunsProperties;

	public static void main(String[] args) {

		SpringApplication.run(PayApplication.class, args);
		logger.info("开始设置IPV4");
		System.setProperty("java.net.preferIPv4Stack", "true");
		logger.info("lediApplication is success!");
	}

	/**
	 * 增加swagger的支持
	 */
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {

		if (gunsProperties.getSwaggerOpen()) {
			registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
			registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
		}
	}
}
